// 个人资料模块，进入前需要验证 是否完成了上一步骤

import store from '../store/store.js'
import Base from '@/components/profile/info'
import Contact from '@/components/profile/contact'
import CheckID from '@/components/profile/checkID'
import AttachMent from '@/components/profile/attachment'
import ZMCheck from '@/components/profile/zm/check'
import ZMAuthorize from '@/components/profile/zm/authorize'
import ZMPhone from '@/components/profile/zm/phone'
import WarrantorManage from '@/components/warrantor/manage'
import WarrantorBase from '@/components/warrantor/info'
import WarrantorCheckID from '@/components/warrantor/checkID'
import WarrantorAttachMent from '@/components/warrantor/attachment'
/* eslint-disable no-new */

// 完善自己的信息的步骤
const checkProfile = (to, from, next) => {
  let step = store.state.profileStep
  let toStep = +to.path[to.path.length - 1]
  let isGetAllProfile = store.state.isGetAllProfile
  if (!isGetAllProfile) {
    next('/profile/manage')
  } else if (toStep <= step && isGetAllProfile) {
    if (toStep > 5 && store.state.profile.zm) {
      next('/profile/step5')
    } else {
      next()
    }
  } else {
    next('/profile/step' + step)
  }
}
// 进入担保人信息管理页面的权限: 必须先完善自己信息
/* const checkWarrantorManage = (to, from, next) => {
  let step = store.state.profileStep
  if (step === 8) {
    next()
  } else {
    next('/profile/manage')
  }
} */
// 担保人步骤先后顺序
const checkWarrantor = (to, from, next) => {
  let step = store.state.warrantorStep
  let toStep = +to.path[to.path.length - 1]
  let isGetAllProfile = store.state.isGetWarrantorAllProfile
  console.log('isGetAllProfile' + isGetAllProfile + '保存的store' + step + '去的step' + toStep)
  if (!isGetAllProfile || toStep !== step) {
    next('/warrantor/manage')
  } else {
    next()
  }
}

const profile = [
  // 个人基本资料
  {
    path: '/profile/step1',
    name: 'Base',
    component: Base,
    beforeEnter: checkProfile
  },
  // 联系人
  {
    path: '/profile/step2',
    name: 'Contact',
    component: Contact,
    beforeEnter: checkProfile
  },
  // 上传身份证
  {
    path: '/profile/step3',
    name: 'CheckID',
    component: CheckID,
    beforeEnter: checkProfile
  },
  // 更多附件资料
  {
    path: '/profile/step4',
    name: 'AttachMent',
    component: AttachMent,
    beforeEnter: checkProfile
  },
  // 验证芝麻分 确认姓名 身份证
  {
    path: '/profile/step5',
    name: 'ZMCheck',
    component: ZMCheck,
    beforeEnter: checkProfile
  },
  // 验证芝麻分 阅读协议
  {
    path: '/profile/step6',
    name: 'ZMAuthorize',
    component: ZMAuthorize,
    beforeEnter: checkProfile
  },
  // 验证芝麻分 确认手机号
  {
    path: '/profile/step7',
    name: 'ZMPhone',
    component: ZMPhone,
    beforeEnter: checkProfile
  },
  // 担保人 信息中心
  {
    path: '/warrantor/manage',
    name: 'WarrantorManage',
    component: WarrantorManage
  },
  // 担保人 基本信息
  {
    path: '/warrantor/step1',
    name: 'WarrantorBase',
    component: WarrantorBase,
    beforeEnter: checkWarrantor
  },
  // 担保人身份证
  {
    path: '/warrantor/step2',
    name: 'WarrantorCheckID',
    component: WarrantorCheckID,
    beforeEnter: checkWarrantor
  },
  // 担保人附件
  {
    path: '/warrantor/step3',
    name: 'WarrantorAttachMent',
    component: WarrantorAttachMent,
    beforeEnter: checkWarrantor
  }
]

export default profile
